package com.spy.system.controller;

import com.spy.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spy.common.annotation.Log;
import com.spy.common.core.controller.BaseController;
import com.spy.common.core.domain.AjaxResult;
import com.spy.common.enums.BusinessType;
import com.spy.system.domain.AdminUser;
import com.spy.system.service.IAdminUserService;
import com.spy.common.utils.poi.ExcelUtil;
import com.spy.common.core.page.TableDataInfo;

/**
 * 管理员Controller
 *
 * @author ruoyi
 * @date 2025-11-09
 */
@RestController
@RequestMapping("/system/admin-user")
@Api(tags = "管理员相关接口")
public class AdminUserController extends BaseController
{
    @Autowired
    private IAdminUserService adminUserService;

/**
 * 查询管理员列表
 */
@PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list")
@ApiOperation("查询管理员列表")
    public TableDataInfo<AdminUser> list(@ApiParam(value = "管理员查询条件") AdminUser adminUser)
    {
        startPage();
        List<AdminUser> list = adminUserService.selectAdminUserList(adminUser);
        return getDataTable(list);
    }

    /**
     * 导出管理员列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @Log(title = "管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出管理员列表")
    public void export(HttpServletResponse response, @ApiParam(value = "管理员查询条件") AdminUser adminUser)
    {
        List<AdminUser> list = adminUserService.selectAdminUserList(adminUser);
        ExcelUtil<AdminUser> util = new ExcelUtil<AdminUser>(AdminUser.class);
        util.exportExcel(response, list, "管理员数据");
    }

    /**
     * 获取管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取管理员详细信息")
    public R<AdminUser> getInfo(@ApiParam(value = "管理员ID", required = true)
                                   @PathVariable("id") Long id)
    {
                return R.ok(adminUserService.selectAdminUserById(id));
    }

    /**
     * 新增管理员
     */
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "管理员", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增管理员")
    public AjaxResult add(@ApiParam(value = "管理员实体", required = true) @RequestBody AdminUser adminUser)
    {
        return toAjax(adminUserService.insertAdminUser(adminUser));
    }

    /**
     * 修改管理员
     */
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改管理员")
    public AjaxResult edit(@ApiParam(value = "管理员实体", required = true)  @RequestBody AdminUser adminUser)
    {
        return toAjax(adminUserService.updateAdminUser(adminUser));
    }

    /**
     * 删除管理员
     */
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "管理员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除管理员")
    public AjaxResult remove(@ApiParam(value = "管理员ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(adminUserService.deleteAdminUserByIds(ids));
    }
}